#ifndef _CPU_COMMON_H_
#define _CPU_COMMON_H_

/*
 *  cpu_common.h
 *  Common functinos for user and kernel parts of tool
 *
 *              CPU Monitor 
 *
 *    Spring Semester.  044800.    Technion.
 *   Copyright (C) 2006  Evgeny Shulman  and Elizabeth Shtrom 
 */
 


// #define CPU_HOOK_PAGE_FAULT
//#ifndef CPU_MONITOR_DEBUG
//#define CPU_MONITOR_DEBUG 
//#endif

#define CHECK_INDEX( index, limit )   \
           (   (  (index) >= ( limit) )  \
            || (  (index) <     0     ) ) ? 0:1  
            
                        	
#define FIX_COUNTER( index, counter,  data_limit,  limit )    \
       if (  (counter) >              (data_limit) )(counter) =  (data_limit);        \
       if ( ( (index)  + (counter)) >= ( limit) )   (counter) =  (limit)  - (index);

int fix_counter_boundaries ( int *index,int  *counter, int data_limit, int table_limit); 
	
/* error values for the page directory & page table reading */
#define INDEX_INVALID 22
#define ENTRY_NOT_PRESENT 33
#define PDE_POINTS_TO_PAGE 44

/* error value for the LDT reading */
#define NO_LDT 55


#define VENDOR_INTEL 1
#define VENDOR_AMD	 2	

/*
 * Macros to help debugging
 */





#undef PDEBUG             /* undef it, just in case */

#ifdef CPU_MONITOR_DEBUG

#ifdef __KERNEL__
     /* This one if debugging is on, and kernel space */
#    define PDEBUG(fmt, args...) printk( KERN_DEBUG "cpu_monitor: " fmt, ## args)
#    define PDEBUG_DISP(fmt, args...) printk( KERN_DEBUG "cpu_monitor: " fmt, ## args)
#    define PDEBUG_WARN(fmt, args...) printk( KERN_WARNING fmt, ## args)

#else
     /* This one for user space */
#    define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
#    define PDEBUG_DISP(fmt, args...) fprintf(stderr, fmt, ## args)

#endif

#else
#  define PDEBUG(fmt, args...) /* not debugging: nothing */
#  define PDEBUG_WARN(fmt, args...) /* not debugging: nothing */
#  define PDEBUG_DISP(fmt, args...) fprintf(stdout, fmt, ## args)

#endif

	
	
	
	
	
	
	
	
#endif


